package com.garden.spingboot_garden.controller;

import com.garden.spingboot_garden.pojo.ResponseMessage;
import com.garden.spingboot_garden.pojo.User;
import com.garden.spingboot_garden.pojo.dto.UserDto;
import com.garden.spingboot_garden.service.UserServiceImplem;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user") //localhost:8081/user/**
@Validated
public class UserController {
    @Autowired
    private UserServiceImplem userService;
    //增加
    @PostMapping("/add")
    public ResponseMessage<User> add(@Valid @RequestBody  UserDto userDto){
        System.out.println("userDto"+userDto);
       User user=  userService.add(userDto);
        return ResponseMessage.success(user);
    }
   // 查询dd
    @GetMapping("/get")
    public ResponseMessage<User> get(@RequestParam Integer userid){
        User user = userService.get(userid);
        return ResponseMessage.success(user);
    }
    // 修改
    @PutMapping("/update" )
    public ResponseMessage<User> update(@Validated @RequestBody  UserDto userDto){
        System.out.println("userDto"+userDto);
        User user=  userService.update(userDto);
        return ResponseMessage.success(user);
    }
    // 删除
    @DeleteMapping("/delete")
    public ResponseMessage<String> delete(@RequestParam Integer userid){
//        User user=  userService.delete(id);
        userService.delete(userid);
        return ResponseMessage.success("delet成功");
    }
    }

